<?php

class National_Model extends CI_Model {
    private $_database;
    public function __construct() {
        parent::__construct();
        $this->_database = $this->db->conn_id;
    }
    	
	/**
    * @author: Pham Van Diep
    * @description: add person national
    * @param integer $intLoginid: user login id
    * @param integer $intPersonalid: Personal id     
    * @param integer
    */
    public function add($intLoginId,$intPersonalId,$strNationalId){
        $stmt = $this->_database->prepare('CALL personals_nationality_add(?,?,?)');
		$stmt->bindParam(1, $intLoginId,     PDO::PARAM_INT, 11);
        $stmt->bindParam(2, $intPersonalId,  PDO::PARAM_INT, 11);
		$stmt->bindParam(3, $strNationalId,  PDO::PARAM_STR, 2);
		$stmt->execute();
        $result = $stmt->fetch();
        return $this->_getErrorCode($result);			
    }
	/**
    * @author: Pham Van Diep
    * @description: delete Personal
    * @param integer $intLoginid: user login id
    * @param integer $intPersonalid: Personal id     
    * @param integer
    */
    public function delete($intLoginid,$intPersonalid){
        $stmt = $this->_database->prepare('CALL personals_nationality_delete(?,?)');
		$stmt->bindParam(1, $intLoginid,     PDO::PARAM_INT, 11);
        $stmt->bindParam(2, $intPersonalid,  PDO::PARAM_INT, 11);
		$stmt->execute();
        $result = $stmt->fetch();
        return $this->_getErrorCode($result);			
    }
	/**
	*	@description: get Error code from query result
	*	@param: mixed query result
	*	@return: int
	*/
	public function _getErrorCode ( $tableData ) {
		return isset($tableData['errCode'])?intval($tableData['errCode']):-1;
	}
}